import { create } from "zustand";
import { DigitalEmployeelogs,eventTypes } from "@/api/Home/home";
import type { typesitem } from "@/api/Home/type";


interface ExceptionState {
  total: number; // “全部”总数
  typesList: typesitem[];
  loading: boolean;

  gettypetotal: () => Promise<void>; // 请求total
}

export const usetypesListtotalStore = create<ExceptionState>((set, get) => ({
  total: 0,
  typesList: [],
  loading: false,

  gettypetotal: async () => {
    set({ loading: true });

    try {
      const typesRes = await eventTypes();
      set({
        typesList: typesRes.data,
      });
      const countRes = await DigitalEmployeelogs({
        Page: 1,
        PageSize: 1, // 只需要 total
      });

      let total = 0;
      if (countRes.code === 1) {
        total = countRes.logs || 0;
      }
      set({
        total,
        loading: false,
      });
    } catch (err) {
      console.error(err);
      set({ loading: false });
    }
  },
}));
